﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>选择组</title>
    <link href="../../Comm/Style/CommStyle.css" rel="stylesheet" type="text/css" />
    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <link href="../../Scripts/easyUI/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../Scripts/easyUI/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../../Scripts/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../Scripts/config.js"></script>
    <script type="text/javascript" src="../../Comm/Gener.js"></script>
    <script src="../../Scripts/EasyUIUtility.js" type="text/javascript"></script>
    <link href="../../Style/skin/adminfont/iconfont.css" rel="stylesheet" />
    <link href="../../Style/skin/css/Default.css" rel="stylesheet" />
    <link href="../../Scripts/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <base target="_self" />
    <script type="text/javascript">

        //页面启动函数.
        var Data;
        $(function () {

            $("#Msg").html("<br/><br/><br/><center><img src=../Img/loading.gif />&nbsp;正在加载,请稍后......</center>");

            var orgNo = GetQueryString("OrgNo");
            if (orgNo == null || orgNo == undefined)
                orgNo = 0;

            //获得该组.
            var stas = new Entities("BP.Port.Teams");
            stas.RetrieveAll();

            var data = new Entities("BP.Port.TeamTypes");
            data.RetrieveAll();
            Data = data;

            BindGroupModel(data, stas);

        });

        function BindGroupModel(groups, stas) {

            AttrOfMInMM = "FK_Station";
            var html = "<table class='table' >";

            html += "<tr>";
            html += "<th colspan=3>";
            html += "<div style='float:left'>";
            html += "<input type=button value='确定' class='cc-btn-tab' onclick='SelectStas();' id='save' />";
            html += "<input type=button value='取消' class='cc-btn-tab' onclick='Close();' id='save' />";
            html += "</div>";

            html += "</th>";
            html += "</tr>";

            for (var i = 0; i < groups.length; i++) {

                var group = groups[i];

                html += "<tr>";
                html += "<th colspan=3>";

                html += "<label for='Group_" + group.No + "'><input type='checkbox'  onclick='CheckAll(this.checked, \"" + group.No + "\");' id='Group_" + group.No + "'  /> " + group.Name + "</label>";

                html += "</th>";
                html += "</tr>";


                var myNum = -1;
                for (var idx = 0; idx < stas.length; idx++) {

                    en = stas[idx];
                    if (en.FK_TeamType != group.No)
                        continue;
                    var lab = en.Name;
                    myNum++;
                    if (myNum == 0)
                        html += "<TR>";
                    html += "<td><label for='CB_" + en.No + "'><input type='checkbox'  name='" + group.No + "' id='CB_" + en.No + "' value='" + en.No + "' /> " + lab + "</label></td>";
                    if (myNum == 2) {
                        html += "</tr>";
                        myNum = -1;
                    }
                }

                if (idx == 1) {
                    html += "<td colspan=2></td>";
                    html += "</tr>";
                }

                if (idx == 2) {
                    html += "<td></td>";
                    html += "</tr>";
                }
            }

            html += "</table>";
            $("#Msg").html(html);
        }

        //选择与取消选择.
        function CheckAll(checked, no) {

            $("input[name='" + no + "']").each(function () {
                this.checked = checked;
            });

        }

        //取消岗位选择
        function Close() {
            if (window.parent != null && window.parent.selectEmpsWindowClose != null) {
                window.parent.selectStasWindowClose("取消");
            }
        }

        //保存.
        var returnVal = []
        function SelectStas() {
            //获取选择的岗位
            for (var i = 0; i < Data.length; i++) {
                $.each($('input:checkbox[name=' + Data[i].No + ']:checked'), function (i, obj) {
                    returnVal.push({ "No": obj.value, "Name": $(obj).parent().text() });

                });
            }
            //No  是返回到别的页面的值
            if (returnVal.length == 0) {
                alert("未选择人员");
            } else {
                var IDs = '';
                var IDNames = '';
                for (var i = 0; i < returnVal.length; i++) {
                    var vals = returnVal[i];
                    if (i + 1 == returnVal.length) {
                        IDs += vals.No;
                        IDNames += vals.Name.trim();
                    } else{
                        IDs += vals.No + ',';
                        IDNames += vals.Name.trim() + ',';
                    }

                }

                    var en = new Entity("BP.CCFast.CCMenu.PowerCenter");
                    en.CopyURL();
                    en.CtrlModel = "Teams";

                    en.IDs = IDs;
                    en.IDNames = IDNames;
                    en.Insert();

                    var url = "../PowerCenter.htm";
                url += "?CtrlObj=" + GetQueryString("CtrlObj") + "&CtrlPKVal=" + GetQueryString("CtrlPKVal") + "&CtrlGroup=" + GetQueryString("CtrlGroup");
                    SetHref(url);

                window.parent.selectStasWindowClose("确定");
            }
        }

    </script>
</head>
<body>


    <div id="Msg"></div>
</body>
</html>
